using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerGames.FarseerPhysics;
using XNA_3DFramWork;

namespace XnaGame
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        private readonly GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;
        private List<XNA_3DFramWork.GameObject> _lGameObject;
        
        static Camera C;
        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            _lGameObject = new List<XNA_3DFramWork.GameObject>();
        }

        
        protected override void Initialize()
        {
            _graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
            _graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
            _graphics.IsFullScreen = false;
            _graphics.ApplyChanges();
            C = new Camera (this);
            _lGameObject.Add(C);
            // TODO: Add your initialization logic here
            Mesh M = new Mesh(this, "sela71", C,new Vector3( 2f),new PhysicsSimulator( new Vector2( 0,0)));
            M.Scale(.02f, .02f, .02f);
            M.Move(300, -30, 0);
            _lGameObject.Add(M);

            base.Initialize();
        }
        protected override void LoadContent()
        {
            
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            foreach (XNA_3DFramWork.GameObject obj in _lGameObject)
                obj.Update();

            base.Update(gameTime);
        }

         
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            foreach (XNA_3DFramWork.GameObject obj in _lGameObject)
                obj.Draw();
            base.Draw(gameTime);
        }
    }
}